<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p id="B-intro">hello world!</p>
    <p id="B-shop">小明去超市买了一包瓜子（<b>22</b>元钱）和一箱饼干（<b>88</b>元钱）和（米<b>100</b>元钱）和（面包<b>100</b>元钱）小明共花了多少钱？</p>
    <p id="B-total-money">$0</p>
    <img src="pic_bulboff.gif" onclick="onLight()" id="B-off-light"/>
    <img src="pic_bulbon.gif" style="display: none" onclick="closeLight()" id="B-on-light" />

<script type="text/javascript">
    var totalMoney = document.getElementById("B-total-money");
    var shop = document.getElementById("B-shop");
    var moneys = shop.getElementsByTagName("b");
    var totalRMBMoney = 0;
    console.log(moneys);
    for (var i = 0;i<moneys.length;i++){
        totalRMBMoney= parseInt(moneys[i].innerText)+totalRMBMoney;
    }
    console.log("----"+totalRMBMoney);

    totalMoney.innerText = "$"+((totalRMBMoney)/6.5285);

    console.log(moneys);
    var sunFlowerMoney = parseInt(moneys[0].innerText);
    console.log(sunFlowerMoney);
    var cookiesMoney = parseInt(moneys[1].innerText);
    console.log(cookiesMoney+sunFlowerMoney);

    var pAll = document.getElementsByTagName("p");
    console.log(pAll);

    for(var i = 0;i<pAll.length;i++){
        console.log(i)
        if(i == 1){
            pAll[i].style.background = "black";
        } else {
            pAll[i].style.background = "red";
        }
    }

    function add(a,b,c){
        var sum = a+b+c;
        console.log(sum);
        return a+b+c;
    }
    var sum = add(10,20,30);
    console.log(sum);
    
    function minus(a,b) {
        console.log(a);
        if(b == undefined){
            b = 0;
            console.log(b);
        }
        return a-b;
    }
    console.log(minus(5));
    
    function take(a,b,c,d) {
        console.log(a,b);
        if(b>a){
            var e;
            e = b;
            b = a;
            a = e;
        }
        console.log(a,b,e);
        return a*b*c*d;
        
    }
    console.log(take(1,2,3,4));
    var intro = document.getElementById("B-intro");

    console.log(intro.id);
    console.log(intro.getAttribute("id"));
    console.log(intro.style);
    console.log(intro.innerHTML);
    console.log(intro.innerText);
    intro.style = "color:red";
    intro.style.color = "green";
    intro.style.background = "yellow";

    function onLight() {
        var onLight = document.getElementById("B-on-light");
        var offLight = document.getElementById("B-off-light");

        onLight.style.display = "inline";
        offLight.style.display = "none";
    }

    function closeLight() {
        var onLight = document.getElementById("B-on-light");
        var offLight = document.getElementById("B-off-light");
        onLight.style.display = "none";
        offLight.style.display = "inline";

    }

    function switchLight1(){
        var light = document.getElementById("B-light");
        console.log(light.src.indexOf("pic_bulboff.gif") > 0);
        console.log(light.src == "pic_bulboff.gif"); // false
        if(light.src.indexOf("pic_bulboff.gif") > 0){
            light.src = "pic_bulbon.gif";
            console.log(true);
        }
        else{
            light.src = "pic_bulboff.gif";
            console.log(false);
        }
        console.log(light.src);
    }
</script>



</body>
</html>